package com.ydy.data.controller;

import com.ydy.common.BaseController;
import com.ydy.common.model.Role;
import com.ydy.common.model.User;
import com.ydy.common.util.ParamsUtil;
import com.ydy.common.vo.PageInfo;
import com.ydy.data.service.RoleInfoService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
public class RoleInfoController extends BaseController {

    @Autowired
    private RoleInfoService roleInfoService;


    /**
     * 查询角色信息
     * @Title: queryRoleInfo
     * @author: dy.yin 2021/4/2 10:04
     * @param: [request]
     * @return: java.lang.Object
     * @throws
     */
    @GetMapping("/queryRoleInfo")
    public Object queryRoleInfo(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        Role role = ParamsUtil.getBeanParam(new Role(),request);

        List<Role> roleList = roleInfoService.queryRoleInfo(role,pageInfo);
        pageInfo.setPageResult(roleList);
        return pageInfo;
    }

    /**
     * 新增或者修改角色
     * @param role
     * @return
     */
    @PostMapping("/submitRoleInfo")
    public Object submitRoleInfo(@RequestBody Role role){
        roleInfoService.submitRoleInfo(role);
        return retResultVo();
    }

    /**
     * 删除角色
     * @param map
     * @return
     */
    @PostMapping("/deleteRoleInfo")
    public Object deleteRoleInfo(@RequestBody LinkedHashMap<String,Object> map){
        String roleCode = MapUtils.getString(map,"roleCode");
        roleInfoService.deleteRoleInfo(roleCode);
        return retResultVo();
    }

}
